package com.yougong.api;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * <p>
 *
 * </p>
 *
 * @author kirk
 * @since 2020/10/19
 */
@SpringBootApplication
@ComponentScans(value = {
//        @ComponentScan("com.yougong.common"),
//        @ComponentScan("com.yougong.security"),
        @ComponentScan("com.yougong.common.exception")
})
@EnableScheduling
public class DataApiApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(DataApiApplication.class, args);
        /*String[] beanNames = run.getBeanDefinitionNames();
        //String[] beanNames = ctx.getBeanNamesForAnnotation(RestController.class);//所有添加该注解的bean
        System.out.println("bean总数:{}" + run.getBeanDefinitionCount());
        for (String str : beanNames) {
            System.out.println(str);
        }*/
    }


    /**
     * 解决刷新问题
     * @return
     */
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        return factory -> {
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
            factory.addErrorPages(error404Page);
        };
    }

}
